package com.dc.di.sf.message;

import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPMessage;
import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
import org.apache.axis2.addressing.AddressingConstants;

import com.dc.di.sf.dt.BusinessData;

public class SoapMessageBuilder {

	public SOAPMessage createSOAPMessage(BusinessData businessData) {
		SOAPFactory factory = new SOAP12Factory();
		SOAPMessage message = factory.createSOAPMessage();
		SOAPEnvelope envelope = factory.createSOAPEnvelope();
		declareSOAPEnvelopeNamespaces(envelope);
		message.setSOAPEnvelope(envelope);
		return message;
	}

	public void declareSOAPEnvelopeNamespaces(SOAPEnvelope envelope) {
		OMFactory factory = envelope.getOMFactory();
		OMNamespace soapns = factory.createOMNamespace(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI,
				SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX);
		OMNamespace addrsns = factory.createOMNamespace(AddressingConstants.Final.WSA_NAMESPACE,
				AddressingConstants.WSA_DEFAULT_PREFIX);
		envelope.setNamespace(soapns);
		envelope.declareNamespace(addrsns);
	}
	
	public static void main(String[] args) {
		SOAPMessage message = new SoapMessageBuilder().createSOAPMessage(null);
		System.out.println(message.getOMDocumentElement().toString());
	}
}
